﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using DataAccess;
using BusinessLogic;

namespace ATM_System_Mock1_G2
{
    public partial class ValidatePIN : System.Web.UI.Page
    {
        CardEntites cardE = new CardEntites();
        CardDA CarD = new CardDA();
        CardBL carBL = new CardBL();
        protected void Page_Load(object sender, EventArgs e)
        {
           // lb_Sesion.Text = Session["CardNo"].ToString();
            txt_PIN.Focus();
        }

        protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
        {
            if(String.IsNullOrWhiteSpace(txt_PIN.Text))
            {
                lb_ThongBao.Text = "* PIN is not null";
            } else
                if(txt_PIN.Text.Length !=6)
                {
                    lb_ThongBao.Text = "* PIN has 6 characters";
                }
                else{
                    if (Session["EnterPIN"] != null)
                    {
                        Session["EnterPIN"] = (int)Session["EnterPIN"] + 1;
                        if ((int)Session["EnterPIN"] == 3)
                        {
                            cardE.CardNo = Session["CardNo"].ToString();                   
                            carBL.Block(cardE);
                            lb_ThongBao.Text = "Block";
                        }
                        else
                        {
                            CheckPIN();
                        }
                    }
                    else {
                        Session["EnterPIN"] = 0;
                        CheckPIN();
                    }
                }
        }
        public void CheckPIN()
        {
            try { 
            cardE.CardNo = Session["CardNo"].ToString();
            cardE.PIN = txt_PIN.Text;
            if (carBL.kiemtraPIN(cardE) == true)
            {
                Response.Redirect("Home.aspx");
            }
            else
            {
                lb_ThongBao.Text = " *Wrong PIN";
            }   
            
            } catch(Exception ex)
            {
                throw ex;
            }
             
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("ValidateCard.aspx");
        }

        protected void btn_Num1_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 1;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 2;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 3;
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 4;
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 5;
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 6;
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 7;
        }

        protected void Button9_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 8;
        }

        protected void Button10_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 9;
        }

        protected void Button12_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += ".";
        }

        protected void Button13_Click(object sender, EventArgs e)
        {
            txt_PIN.Text += 0;
        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            txt_PIN.Text = "";
        }
    }
}